package me.jessyan.armscomponent.app.mvp.ui.activity.learn;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import java.util.ArrayList;

import butterknife.BindView;
import me.jessyan.armscomponent.commonres.widget.wheelview.TimePickerBuilder;
import me.jessyan.armscomponent.commonres.widget.wheelview.TimePickerView;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import me.jessyan.armscomponent.app.R;
import me.jessyan.armscomponent.app.di.component.DaggerTimeSettingComponent;
import me.jessyan.armscomponent.app.mvp.contract.learn.TimeSettingContract;
import me.jessyan.armscomponent.app.mvp.presenter.learn.TimeSettingPresenter;
import me.jessyan.armscomponent.app.mvp.ui.widget.CircleProcessView;
import me.jessyan.armscomponent.app.mvp.ui.widget.CircleProcessViewData;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description: 我的学习计划-计划日志  116
 * <p>
 * Created by MVPArmsTemplate on 08/27/2021 22:27
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@Route(path = RouterHub.LEARNING_TIMESETTINGACTIVITY)
public class TimeSettingActivity extends BaseActivity<TimeSettingPresenter> implements TimeSettingContract.View, CompoundButton.OnCheckedChangeListener {

    @BindView(R.id.myView)
    CircleProcessView myView;
    @BindView(R.id.time_setting_switch)
    Switch time_setting_switch;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerTimeSettingComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.learning_activity_time_setting; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        ArrayList<CircleProcessViewData> list = new ArrayList();
        CircleProcessViewData viewData = new CircleProcessViewData(45, "abc");
        CircleProcessViewData viewData1 = new CircleProcessViewData(315, "abc");
        list.add(viewData);
        list.add(viewData1);
        myView.setData(list);
        time_setting_switch.setOnCheckedChangeListener(this);
    }

    @Override
    public void showLoading() {
    }

    @Override
    public void hideLoading() {
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    private TimePickerView timePickerView;

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            timePickerView = new TimePickerBuilder(getActivity(), (date1, v) -> {
                Toast.makeText(getActivity(), date1.toString(), Toast.LENGTH_SHORT).show();
            })
                    .setLayoutRes(R.layout.custom_time_pickerview, v -> {
                        final TextView tvSubmit = v.findViewById(R.id.tv_confirm);
                        TextView tvCancel = v.findViewById(R.id.tv_cancel);
                        tvSubmit.setOnClickListener(v12 -> {
                            timePickerView.returnData();
                            timePickerView.dismiss();
                        });
                        tvCancel.setOnClickListener(v1 -> timePickerView.dismiss());
                    })
                    .setType(new boolean[]{false, false, false, true, true, false})
                    .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                    .setDividerColor(Color.RED)
                    .build();

            timePickerView.show();
        }
    }
}
